<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="tag" uri="com.sand.myTag" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>分步表单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/public.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/js/lay-module/step-lay/step.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/jq-module/zyupload/zyupload-1.0.0.min.css" media="all">
    <style>
        .required:after {
            top: 6px;
            right: 5px;
            color: red;
            content: '*';
            position: absolute;
            margin-left: 4px;
            font-weight: 700;
            line-height: 1.8em;
        }
        #file1{
            margin-left: 30px;
            border: solid 1px whitesmoke;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 40px;">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                        <div carousel-item>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 1000px;padding-top: 40px;">
                                    <input type="hidden" name="customerId" value="${upCustomer.rid}">
                                    <table>
                                        <tr>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label">办理人:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="customerName" value="${upCustomer.companyName}" placeholder="请输入办理人" class="layui-input" />
                                                </div>
                                            </div></td>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label">客户类型:</label>
                                                <div class="layui-input-block">
                                                    <select name="customerType" lay-verify="required"  placeholder="请选择类型">
                                                        <option value="国营企业" selected>国营企业</option>
                                                        <option value="私营企业">私营企业</option>
                                                        <option value="个体户">个体户</option>
                                                    </select>
                                                </div>
                                            </div></td>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label">法人:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="legalPerson" value="" class="layui-input" placeholder="请输入法人" />
                                                </div>
                                            </div></td>
                                        </tr>
                                        <tr>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label">联系电话:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="tel" value="${upCustomer.tel}" class="layui-input" placeholder="请输入联系电话" />
                                                </div>
                                            </div></td>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label">邮箱:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="email" value="" class="layui-input" placeholder="请输入邮箱" />
                                                </div>
                                            </div></td>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label">地址:</label>
                                                <div class="layui-input-block">
                                                    <select name="address" lay-search="">
                                                        <option value="">选择或搜索城市</option>
                                                        <c:forEach items="${city}" var="ite">
                                                            <option value="${ite.typeName}">${ite.typeName}</option>
                                                        </c:forEach>
                                                    </select>
                                                </div>
                                            </div></td>
                                        </tr>
                                        <tr>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label required">跟进人员:</label>
                                                <div class="layui-input-block">
                                                    <input type="hidden" name="followPerson" id="followPerson" value="${user.rid}">
                                                    <input type="text" name="followPerson1" lay-verify="required" lay-reqtext="跟进人不能为空" placeholder="请选择跟进人员" value="${user.uName}" autocomplete="off" class="layui-input" id="demo2">
                                                </div>
                                            </div></td>
                                            <td>    <div class="layui-form-item">
                                                <label class="layui-form-label required">商品:</label>
                                                <div class="layui-input-block">
                                                    <input type="hidden" name="goods" id="goods" value="">
                                                    <input type="text" lay-verify="required" lay-reqtext="请选择商品" name="goods1" value="" autocomplete="off" class="layui-input" id="demo3">
                                                </div>
                                            </div></td>
                                            <td>    <div class="layui-form-item">
                                                <label class="layui-form-label ">订单状态:</label>
                                                <div class="layui-input-block">
                                                    <select name="state" lay-verify="required" lay-search="">
                                                        <option value="未发货" selected>未发货</option>
                                                        <option value="已签收">已签收</option>
                                                        <option value="开始发货">开始发货</option>
                                                    </select>
                                                </div>
                                            </div></td>
                                        </tr>
                                        <tr>
                                            <td> <div class="layui-form-item">
                                                <label class="layui-form-label required">订单金额:</label>
                                                <div class="layui-input-block">
                                                    <input type="number" name="orderMoney" id="orderMoney" placeholder="请填写订单金额" value="" class="layui-input" lay-verify="number" required>
                                                </div>
                                            </div></td>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label">记录内容:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="recordContent" value="下订单" class="layui-input" placeholder="请输入记录内容" />
                                                </div>
                                            </div></td>
                                            <td>    <div class="layui-form-item">
                                                <label class="layui-form-label required ">下次跟进:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="nextFollow" id="nextFollow" lay-verify="date" autocomplete="off" class="layui-input">
                                                </div>
                                            </div></td>
                                        </tr>
                                        <tr>
                                            <td colspan="2"><div class="layui-form-item">
                                                <label class="layui-form-label">备注:</label>
                                                <div class="layui-input-block">
                                                    <textarea placeholder="请输入备注" name="remarks" class="layui-textarea"></textarea>
                                                </div>
                                            </div></td>
                                            <td><div class="layui-form-item">
                                                <div class="layui-input-block">
                                                    <button class="layui-btn" lay-submit lay-filter="formStep">
                                                        &emsp;下一步&emsp;
                                                    </button>
                                                </div>
                                            </div></td>
                                        </tr>
                                    </table>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 700px;padding-top: auto;">
                                    <table>
                                        <tr>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label">办理人:</label>
                                                <div class="layui-input-block">
                                                    <input type="hidden" id="customerId" name="customerId">
                                                    <input type="text" name="customerName" id="customerName" value="${upCustomer.companyName}" disabled class="layui-input" />
                                                </div>
                                            </div></td>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label">订单金额:</label>
                                                <div class="layui-input-block">
                                                    <input type="number" name="money" id="orderMoney2" placeholder="请填写订单金额" value="" class="layui-input" lay-verify="number">
                                                </div>
                                            </div></td>
                                        </tr>
                                        <tr>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label ">是否分期:</label>
                                                <div class="layui-input-block">
                                                    <input type="checkbox" name="stages" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
                                                        <div style="float: right;display: none" id="s2" >
                                                            <input type="radio" name="s1" id="d1" value="" title="3期" checked="">
                                                            <input type="radio" name="s1" id="d2" title="6期" value="" >
                                                            <input type="radio" name="s1" id="d3" title="12期" value="" >
                                                        </div>
                                                </div>
                                            </div></td>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label ">合同状态:</label>
                                                <div class="layui-input-block">
                                                    <select name="state" lay-search="">
                                                        <option value="驳回">驳回</option>
                                                        <option value="审核中" selected>审核中</option>
                                                        <option value="通过">通过</option>
                                                    </select>
                                                </div>
                                            </div></td>
                                        </tr>
                                        <tr>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label ">合同期限:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="htEndtime" placeholder="请输入合同期限" value="" class="layui-input">
                                                </div>
                                            </div></td>
                                            <td><div class="layui-form-item">
                                                <label class="layui-form-label required ">签订时间:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="date" id="date" lay-verify="date" autocomplete="off" class="layui-input">
                                                </div>
                                            </div></td>
                                        </tr>
                                        <tr>
                                            <td colspan="2"><div class="layui-form-item">
                                                <label class="layui-form-label ">合同内容:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="content" id="content1" placeholder="请输入合同内容" value="" class="layui-input">
                                                </div>
                                            </div></td>
                                        </tr>
                                        <tr>
                                            <td colspan="2"><div class="layui-form-item layui-form-text">
                                                <label class="layui-form-label">备注:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" name="remarks" placeholder="请输入备注" value="" class="layui-input">
                                                </div>
                                            </div></td>
                                        </tr>
                                        <tr>
                                            <td colspan="2"><div class="layui-form-item">
                                                <div class="layui-input-block">
                                                    <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                                    <button class="layui-btn" lay-submit lay-filter="formStep2">
                                                        &emsp;确认入款&emsp;
                                                    </button>
                                                    <input type="file" id="file1" name="upLoads" multiple>
                                                </div>
                                            </div></td>
                                        </tr>
                                    </table>
                                </form>
                            </div>
                            <div>
                                <div style="text-align: center;margin-top: 90px;">
                                    <i class="layui-icon layui-circle"
                                       style="color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;">&#xe605;</i>
                                    <div style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">
                                        办理成功
                                    </div>
                                    <div style="font-size: 14px;color: #666;margin-top: 20px;">预计两小时到账</div>
                                </div>
                                <div style="text-align: center;margin-top: 50px;">
                                    <button class="layui-btn next">再入一笔</button>
                                    <button class="layui-btn layui-btn-primary end">返回</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/layui/js/lay-config.js?v=1.0.4" charset="utf-8"></script>

<script src="${pageContext.request.contextPath}/layui/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/layui/lib/jq-module/zyupload/zyupload-1.0.0.min.js" charset="utf-8"></script>
<script>
    layui.use([ 'form', 'step', 'tableSelect', 'laydate'], function () {
        var $ = layui.$,
            form = layui.form,
            tableSelect = layui.tableSelect,
            laydate = layui.laydate,
            step = layui.step;

        form.on('switch(switchTest)', function (data) {
            $("#s2").toggle();
            var sum=$("#orderMoney2").val();
            $("#d1").val("3 X "+(sum/3).toFixed(2))
            $("#d2").val("6 X "+(sum/6).toFixed(2))
            $("#d3").val("12 X "+(sum/12).toFixed(2))
            $("#dt1").text("3 X "+(sum/3).toFixed(2))
            $("#dt2").text("6 X "+(sum/6).toFixed(2))
            $("#dt3").text("12 X "+(sum/12).toFixed(2))

        });

        $("#s2").click(function (){
            $("#content1").val($("#demo3").val()+",分期:"+$("input[name='s1']:checked").val());
        })

        laydate.render({
            elem: '#nextFollow'
        });
        laydate.render({
            elem: '#date'
        });

        tableSelect.render({
            elem: '#demo2',
            searchKey: 'we',
            checkedKey: 'rid',
            table: {
                url: '${pageContext.request.contextPath}/user_queryUserLimit',
                cols: [[
                    {
                        type: 'radio' }
                    ,{
                        field: 'rid',align:'center', width: 80, title: '编号', sort: true }
                    , {
                        field: 'uName',align:'center', title: '姓名', minWidth: 150
                    }
                ]]
            },
            done: function (elem, data) {
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.uName)
                    $("#followPerson").val(item.rid)
                })
                elem.val(NEWJSON.join(","))
            }
        })
        tableSelect.render({
            elem: '#demo3',
            searchKey: 'we',
            checkedKey: 'rid',
            table: {
                url: '${pageContext.request.contextPath}/goods_queryGoodsLimit',
                cols: [[
                    {
                        type: 'radio' }
                    ,{
                        field: 'rid',align:'center', width: 80, title: '编号', sort: true }
                    , {
                        field: 'goodsName',align:'center', width: 150, title: '商品名称' }
                    , {
                        field: 'price',align:'center', width: 80, title: '单价'}
                    , {
                        field: 'remarks',align:'center', width: 150, title: '备注' }
                ]]
            },
            done: function (elem, data) {
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.goodsName);
                    $("#goods").val(item.rid);
                    $("#orderMoney").val(item.price);
                    $("#orderMoney2").val(item.price);
                    $("#content1").val(item.goodsName);

                    // var sum=item.price;
                    // $("#d1").val("3*"+sum/3)
                    // $("#d2").val("6*"+sum/6)
                    // $("#d3").val("9*"+sum/9)
                    // $("#d1").attr("title","3*")
                })
                elem.val(NEWJSON.join(","))
            }
        })

        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '750px',
            height: '500px',
            stepItems: [{
                title: '下订单'
            }, {
                title: '合同信息'
            }, {
                title: '完成'
            }]
        });


        form.on('submit(formStep)', function (data) {
            $.ajax({
                url:"${pageContext.request.contextPath}/order_downOrder",
                type:"post",
                data:"data="+JSON.stringify(data.field),
                dataType:"text",
                success:(rs)=>{
                    if(rs=="OK"){
                        layer.msg("下单成功",{icon:1,time:500},()=>step.next('#stepForm'));
                    }else{
                        layer.msg("下单失败",{icon:2,time:500});
                    }
                }
            })
            return false;
        });

        form.on('submit(formStep2)', function (data) {
            let formData = new FormData();
            let obj=$("#file1")[0].files;
            for(let i=0;i<obj.length;i++){
                formData.append("upLoads",obj[i]);
            }
            formData.append("data",JSON.stringify(data.field))
            $.ajax({
                url:"${pageContext.request.contextPath}/contract_addContract",
                type:"post",
                data:formData,
                dataType:"text",
                processData: false,
                contentType: false,
                success:(rs)=>{
                    if(rs=="OK"){
                        layer.msg("提交成功",{icon:1,time:500},()=>step.next('#stepForm'));
                    }else{
                        layer.msg("提交失败",{icon:2,time:500});
                    }
                }
            })
            return false;
        });

        if("${contractGo}"=="OK"){
            step.next('#stepForm');
            $("#customerId").val("${upOrder.customerId}");
            $("#customerName").val("${upOrder.customerIds}");
            $("#orderMoney2").val("${upOrder.orderMoney}");
            $("#content1").val("${upOrder.goodss}");
            $("#demo3").val("${upOrder.goodss}");
        }

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            step.next('#stepForm');
        });

        $('.end').click(function () {
            parent.location.reload();
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        });
    })

</script>
</body>
</html>